<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
	    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	    <title>重置密码</title>
	    <link rel="stylesheet" href="../../css/mui.min.css" />
	    <link rel="stylesheet" href="../../css/own.css" />
	    <script type="text/javascript" src="../../js/mui.min.js"></script>   
	    <script type="text/javascript" src="../../js/common.js"></script>
	    <script src="../../js/jquery-1.11.3.js"></script>
	    <link rel="stylesheet" href="../../css/quotation.css" />
	    <style>
	    	body{
	    		background-color: #2B2B2B;
	    	}
	    </style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav own-topbg">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back"><i>返回</i></a>
			<h1 class="mui-title">重置密码</h1>		
			<a href="javascript:void(0)" class="top-tel" id="online">在线客服</a>
		</header>
		<div class="mui-content" >
			<div id="inputList">
				<div class="commStyle">
					<label>重置密码：</label>
					<input type="password"  placeholder="输入6-16位字母和数字组合" id='password' oninput="checkValue()"/>
					<img src="../../images/close.png" id="accountClear">
				</div>
				<div class="commStyle">
					<label>确认密码：</label>
					<input type="password"  placeholder="请再次输入密码" id="confirm_password" oninput="checkValue()"/>
					<img src="../../images/close.png" id="passwordClear">
				</div>
				<div class="mui-content-padded">
					<button  class="mui-btn mui-btn-block" id="operateLogin">确认提交</button>
				</div>
			</div>
			<p id="callService">客服热线：400-180-1860</p>
		</div>
		<script>
			tzdr.online();
			mui.plusReady(function(){
				document.getElementById("operateLogin").addEventListener("tap",function(){
					registUser()
				});
				var width=window.innerWidth;
				$(".commStyle input").css({
							"width":width-120+"px",
				});
				function registUser(){
					var web=plus.webview.currentWebview()
					var mobile=web.mobile;
					var code = web.userCode;
					var password= document.getElementById("password").value;
					var password2= document.getElementById("confirm_password").value;
					if(mui.isnull(password)){
							mui.toast("登录密码不能为空！");
							return;
						}
						if(mui.isnull(password2)){
							mui.toast("确认密码不能为空！");
							return;
						}
						
						if(!tzdr.validate_password(password)){
							mui.toast("密码由6-16位数字和字母组成。");
							return;
						}
						//校验登录密码与确认密码是否一致
						if(password!=password2){
							mui.toast("两次输入密码不一致，请重新输入");
							return;
						}
					mui.app_request('/reset_password',{ 
	      			 'mobile':mobile,
				    'password':password,
				    'code':code
		      	},function(result){ 
		      				//updateMockAccount(mobile,password);
		    				mui.toast("密码重置成功，请重新登录！"); 
      						mui.openWindow("login.html");
		      				return;
		      			
		      		},function(result){
		      			if(result.code==2){
		      				mui.toast("注册失败！");
		      				return;
		      			}else if(result.code==5){
		      				mui.toast("验证码失效！");
		      				return;
		      			}else if(result.code==6){
		      				mui.toast("推广码错误！"); 
		      				return;
		      			}else{
		      				mui.toast("手机号码不存在，请确认后再试！");
		      				return;
		      			}
		      		
		      		});
		      		
				}
					function updateMockAccount(username,password){
						mui.app_request("/mock/trade/updateMock",
									{"username":username,"password":password},
									function(result){
										console.log("修改模拟账号成功");
									},function(result){
										console.log("修改模拟账号失败");
									}
								)
    				}
				 /*绑定事件
				 */
				$("#accountClear").click(function(){
					$("#password").val("");
					checkValue();
				});
				$("#passwordClear").click(function(){
					$("#confirm_password").val("");
					checkValue();
				});
				document.getElementById("telBtn").addEventListener("tap",function(){
		    			mui.callService();
		    	});
				document.getElementById("callService").addEventListener("tap",function(){
		    			mui.callService();
		    	});
			})
			
			
			/*按钮变色*/
			function checkValue(){
				var password=$("#password").val();
				var confirm_password=$("#confirm_password").val();
				if(password.length>0 && confirm_password.length>0){
					$("#operateLogin").css({
						"background-color":"#fcc900"
					});
				}else{
					$("#operateLogin").css({
						"background-color":"#cccccc"
					});
				}
				if(password=="" || password==null || password.length==0) {
					$("#accountClear").css({
						"display": "none"
					});
				}
				if(confirm_password=="" || confirm_password==null || confirm_password.length==0){
					$("#passwordClear").css({
					"display":"none"
					});
				};
				if(password.length>0){
					$("#accountClear").css({
						"display":"block"
					});
				}
				if(confirm_password.length>0){
					$("#passwordClear").css({
						"display":"block"
					});
				}
			}
			/*
			 * 下方的客服热线
			 */
				var i = 0 ;
				$(window).resize(function() {
					if(i % 2 == 0){  
						$("#callService").css("display","none");
					}else{
						$("#callService").css("display","block");
					}
					i++; 
				});
		</script>
	</body>
</html>
